// 项目配置检查工具
class ConfigChecker {
  // 检查app.json配置
  static checkAppConfig() {
    const issues = [];

    try {
      // 这里可以添加更多配置检查逻辑
      console.log("✅ 项目配置检查通过");
      return {
        success: true,
        issues: [],
      };
    } catch (error) {
      issues.push(`配置检查失败: ${error.message}`);
      return {
        success: false,
        issues,
      };
    }
  }

  // 检查权限配置
  static checkPermissionConfig() {
    const issues = [];

    // 检查位置权限配置
    if (!wx.getSetting) {
      issues.push("微信API不可用，请检查运行环境");
    }

    return {
      success: issues.length === 0,
      issues,
    };
  }

  // 检查插件配置
  static checkPluginConfig() {
    const issues = [];

    // 检查是否还有插件配置残留
    try {
      const appConfig = require("../app.json");
      if (appConfig.plugins && Object.keys(appConfig.plugins).length > 0) {
        issues.push("检测到插件配置，建议移除以避免授权问题");
      }
    } catch (error) {
      // 忽略文件读取错误
    }

    return {
      success: issues.length === 0,
      issues,
    };
  }

  // 完整配置检查
  static async fullCheck() {
    const results = {
      appConfig: this.checkAppConfig(),
      permissionConfig: this.checkPermissionConfig(),
      pluginConfig: this.checkPluginConfig(),
    };

    const allIssues = [
      ...results.appConfig.issues,
      ...results.permissionConfig.issues,
      ...results.pluginConfig.issues,
    ];

    const success = allIssues.length === 0;

    console.log("🔍 项目配置检查结果:");
    console.log(`✅ 应用配置: ${results.appConfig.success ? "通过" : "失败"}`);
    console.log(
      `✅ 权限配置: ${results.permissionConfig.success ? "通过" : "失败"}`
    );
    console.log(
      `✅ 插件配置: ${results.pluginConfig.success ? "通过" : "失败"}`
    );

    if (allIssues.length > 0) {
      console.log("⚠️ 发现的问题:");
      allIssues.forEach((issue, index) => {
        console.log(`${index + 1}. ${issue}`);
      });
    } else {
      console.log("🎉 所有配置检查通过！");
    }

    return {
      success,
      results,
      issues: allIssues,
    };
  }
}

export default ConfigChecker;
